/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package matris.vue;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComponent;

/**
 *
 * @author YOUCEF
 */
public class Avatar extends JComponent implements Runnable{
 
    private Image imgRun;
    private Image imgStop;
    private Image imgJump;
    private Image img;
    
    public Avatar(){
        imgRun = Toolkit.getDefaultToolkit().createImage("run.gif");
        imgStop = Toolkit.getDefaultToolkit().createImage("mario.gif");
        imgJump = Toolkit.getDefaultToolkit().createImage("saut.gif");
        this.img= this.imgStop;
    }

    @Override
    public void paintComponent(Graphics g){
        super.paintComponent(g);
        g.drawImage(img, 0, 0, null);
    }
    
    public void setImageJump(){
        this.img = this.imgJump;
        this.repaint();
    }
    
    public void setImageRun(){
        this.img = this.imgRun;
        this.repaint();
    }
    
    @Override
    public void run(){
        while (true) {
            try {
                Thread.sleep(500);
                this.setImageRun();
                Thread.sleep(5000);
                this.setImageJump();
            } catch (InterruptedException ex) {
                Logger.getLogger(Avatar.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        }
    }
    
}
